package cn.taofuxn.sale.util;

import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;

/**
 * ProjectName : leuom-devicemanager-service
 * PackageName : com.goldmsg.leuom.mgr.utils
 * Created by Wong
 * Date: 2018/3/7
 * Time: 17:32
 */
public class SpringContextUtil {
	
	private static ApplicationContext applicationContext;
	
	//获取上下文
	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}
	
	//设置上下文
	public static void setApplicationContext(ApplicationContext applicationContext) {
		SpringContextUtil.applicationContext = applicationContext;
	}
	
	//通过名字获取上下文中的bean
	public static Object getBean(String name){
		return applicationContext.getBean(name);
	}
	
	//通过类型获取上下文中的bean
	public static Object getBean(Class<?> requiredType){
		return applicationContext.getBean(requiredType);
	}
	
	//获取上下文中的坏境信息
	public static Environment getEnvironment(){
		return applicationContext.getEnvironment();
	}
}
